﻿#include "ais_frame.h"

CAGD::AIS_Frame::AIS_Frame(Point pos, Size size) : m_pos(pos), m_size(size)
{
    // 设置背景色
    m_info.color = {0.3, 0.3, 0.3, 1.0};
}

bool CAGD::AIS_Frame::MoveTo(Point pos)
{
    // 隐藏状态不交互，不活跃状态不交互
    if (m_info.status == AIS_Status::HIDDEN || m_info.active == false)
        return false;

    // 临时记录
    bool hang = false;
    auto tmp = m_info.status;
    m_info.status = AIS_Status::NONE;

    if (pos.x > m_pos.x && pos.x < m_pos.x + m_size.x && pos.y > m_pos.y && pos.y < m_pos.y + m_size.y)
    {
        hang = true;
        if (tmp != AIS_Status::TOUCH)
            m_info.status = AIS_Status::HANG;
        else
            m_info.status = tmp;

        // 计算深度
        SetDepth(-2);
    }

    return hang;
}

bool CAGD::AIS_Frame::Move(Point pos)
{
    auto &info = m_context.GetInfo();
    m_pos.x += pos.x - info.points[1].x;
    m_pos.y += pos.y - info.points[1].y;

    // 刷新着色器
    UpdateArray();

    return true;
}

CAGD::AIS_Type CAGD::AIS_Frame::GetType() const
{
    return AIS_Type::FRAME;
}

void CAGD::AIS_Frame::UpdateInfo()
{
    // do nothing
}

void CAGD::AIS_Frame::RecvMessage(Message mess)
{
}

CAGD::Point &CAGD::AIS_Frame::GetPosition()
{
    return m_pos;
}

CAGD::Size &CAGD::AIS_Frame::GetSize()
{
    return m_size;
}

std::vector<std::string> &CAGD::AIS_Frame::GetTexts()
{
    return m_texts;
}
